package com.android.bonn.fast.adapter;

import android.content.Context;
import android.content.res.Resources;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

/**
 * author huangyunlin@snqu.com
 * date 2018/10/16
 * description
 */
abstract class CellViewHolder<T> extends RecyclerView.ViewHolder {

    private SimpleCellDelegateAdapter adapter;
    private OnItemViewClickListener<T> mItemViewClickListener;

    void setOnItemViewClickListener(OnItemViewClickListener<T> mListener) {
        this.mItemViewClickListener = mListener;
    }

    public void setAdapter(SimpleCellDelegateAdapter adapter) {
        this.adapter = adapter;
    }

    CellViewHolder(@NonNull View view) {
        super(view);
    }

    public SimpleCellDelegateAdapter getCurrentAdapter() {
        return adapter;
    }

    public abstract void onBind(T d, int position);

    public void onBind(T d, int position, @NonNull List<Object> payloads) {
    }

    public Context getContext() {
        return itemView.getContext();
    }

    public Resources getResources() {
        return getContext().getResources();
    }

    public void onItemViewClick(View view, int position, T data) {
        if (mItemViewClickListener != null) {
            mItemViewClickListener.onItemViewClick(view, position, data);
        }
    }
}
